package top.wardyan.wmes.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollectionUtil;
import top.wardyan.wmes.rfid.vo.BillNo;

public class BillNoUtil {

	
	
	/**
	 * 2021-12-30
	 * @param billNos
	 * @return
	 */
	public static Map<Integer, BillNo> map(List<BillNo> billNos){
		Map<Integer, BillNo> rs = new HashMap<>();
		if(billNos == null) {
			billNos = new ArrayList<>();
		}
		for(var b : billNos) {
			rs.put(b.getBillNo(), b);
		}
		return rs;
	}
	/**
	 * 2;3;4:裁剪;剪线;包装 以后再考虑这个格式
	 * @param billNos
	 * @param sperator
	 * @return
	 */
	public static String mapToStr(List<BillNo> billNos, String sperator) {
		if(billNos == null) {
			billNos = new ArrayList<>();
		}
		var no = CollectionUtil.join(billNos.stream().map(new Function<BillNo, Integer>(){
			@Override
			public Integer apply(BillNo t) {
				return t.getBillNo();
			}
		}).collect(Collectors.toList()), ",");
		var name = CollectionUtil.join(billNos.stream().map(new Function<BillNo, Integer>(){
			@Override
			public Integer apply(BillNo t) {
				return t.getBillNo();
			}
		}).collect(Collectors.toList()), ",");
		return String.format("%s:%s", no, name);
	}
}
